﻿@using zichan.Entity
@using zichan.Common;
@model List<Role>
@{
    ViewBag.Title = "角色管理";
}

@section Pagetitle{
    @AdminCommon.PageTitle("角色管理", "添加/删除/修改")
}

@helper ShowPower(string powers)
{
Dictionary<int, string> idname = (Dictionary<int, string>)ViewBag.Menus;
List<int> ids = powers.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(o => Convert.ToInt32(o)).ToList();
    @(string.Join(",", idname.Where(o => ids.Contains(o.Key)).Select(o => o.Value).ToArray()));
}

<div class="portlet">
    <div class="portlet-title">
        <div class="caption">
            <i class="fa fa-table"></i>角色列表
        </div>
        <div class="actions">
            @if (zichan.Common.PowerHelp.Check("role", "create"))
            {
                <a href="@Url.Action("create", "role")" class="btn default yellow-stripe">
                    <i class="fa fa-plus"></i>
                    <span class="hidden-480">角色添加</span>
                </a>
            }
        </div>
    </div>
    <div class="portlet-body">
        <div class="table-container">

            <div class="dataTables_wrapper dataTables_extended_wrapper no-footer">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="table-group-actions pull-right">
                            @using (Html.BeginForm("index", "role", FormMethod.Get, new { @class = "form-inline" }))
                            {
                                <div class="form-group">
                                    <input type="text" placeholder="菜单名称" name="name" value="@ViewBag.name" class="form-control input-small input-sm" />
                                </div>
                                <div class="form-group">
                                    <input type="text" placeholder="Controller" name="cller" value="@ViewBag.cller" class="form-control input-sm" />
                                </div>
                                <div class="form-group">
                                    <input type="text" placeholder="Action" name="act" value="@ViewBag.act" class="form-control input-small input-sm" />
                                </div>
                                <button class="btn btn-sm yellow table-group-action-submit"><i class="fa fa-check"></i> 搜索</button>

                            }
                        </div>
                    </div>
                </div>
                <div class="table-scrollable">
                    <table class="table  table-hover">
                        <thead>
                            <tr class="heading">
                                <th style=" width:30px;"> # </th>
                                <th style=" width:100px;">名称</th>
                                <th>权限</th>
                                <th style=" width:140px;"></th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (Role r in Model)
                            {
                                <tr>
                                    <td>@r.Id</td>
                                    <td>@r.Name</td>
                                    <td>@ShowPower(r.Powers)</td>
                                    <td>
                                        @if (PowerHelp.Check("role", "edit"))
                                        {
                                            <a href="@Url.Action("edit", "role", new { id=r.Id})" class="btn default btn-xs purple">
                                                <i class="fa fa-edit"></i> 编辑
                                            </a>
                                        }
                                        @if (PowerHelp.Check("role", "delete"))
                                        {
                                            <a href="@Url.Action("delete", "role", new { id=r.Id})" class="btn default btn-xs black">
                                                <i class="fa fa-trash-o"></i> 删除
                                            </a>
                                        }
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-md-12">

                    </div>
                </div>

            </div>

        </div>
    </div>
</div>
